package com.cms.cmsbackend.service;

import com.cms.cmsbackend.mapper.CustomerMapper;
import com.cms.cmsbackend.pojo.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class CustomerService {

    @Autowired
    private CustomerMapper customerMapper;



    public Customer select(String username,String password){
        if("".equals(username)|| null == username || "".equals(password) || null == password){
            return null;
        }
        Example example=new Example(Customer.class);
        example.createCriteria()
                .andEqualTo("username",username)
                .andEqualTo("password",password);

        List<Customer> list=customerMapper.selectByExample(example);
        //如果list集合为空或者是里面元素为空，代表查不到数据
        if (list == null || list.size() <=0){
            return null;
        }else {
            //返回第一个元素
            return list.get(0);
        }


    }
}
